﻿using Assets.BattleSystem.EnemyConfigs;
using Assets.Script.BattleSystem.Core;
using Script.NetSystem.Services.RoomAndBattle.BattleService;
using Script.UiSystem;
using Script.UiSystem.Room;
using SimpleTools.Json;
using UnityEngine;
using UnityEngine.SceneManagement;

namespace Script.NetSystem.Services.RoomAndBattle.RoomService.Handler
{
    public class StartBattle : IRoomHandler
    {
        public void Handler(RoomController controller, JsonData jsonData)
        {
            
            // roomClient.CloseConnect();
            
            JsonData send = new JsonData();
            send.Add("id", GlobalCache.PlayerNetId);
            
            BattleController.Instance.BattleClient = new BattleClient(
                jsonData.GetInt("port"), 
                send.Json,
                delegate
                {
                    SceneManager.LoadScene("Scenes/BattleTemp");
                }, 
                delegate
                {
                    BattleController.Instance.PollHandler.Invoke();
                });
        }
    }
}